<template>
  <a-card :bordered="false">
    <div class="card-title">{{ $route.meta.title }}</div>
    <div class="table-operator">
      <!-- 搜索板块 -->
      <a-row class="row-item-search">
        <a-form class="search-form" :form="searchForm" layout="inline" @submit="handleSearch">
          <a-form-item label="手机号搜索">
            <a-input v-decorator="['search']" placeholder="请输入客户完整手机号" />
          </a-form-item>
          <a-form-item label="报名时间">
            <a-range-picker format="YYYY-MM-DD" v-decorator="['betweenTime']" />
          </a-form-item>
          <a-form-item label="疾病类型">
            <a-select placeholder="请选择" v-decorator="['illness_id']">
              <a-select-option v-for="(item,i) in illnessList" :key="i" :value="item.id">
                {{ item.tag }}
              </a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="参与进度">
            <a-select placeholder="请选择" v-decorator="['status']">
              <a-select-option value="1">
                待审核
              </a-select-option>
              <a-select-option value="2">
                待签到
              </a-select-option>
              <a-select-option value="3">
                待知情
              </a-select-option>
              <a-select-option value="4">
                待筛选
              </a-select-option>
              <a-select-option value="5">
                待入组
              </a-select-option>
              <a-select-option value="6">
                实验中
              </a-select-option>
              <a-select-option value="7">
                已完成
              </a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item class="search-btn">
            <a-button type="primary" icon="search" html-type="submit">搜索</a-button>
          </a-form-item>
        </a-form>
      </a-row>
    </div>
    <s-table
      ref="table"
      :loading="isLoading"
      :columns="columns"
      :data="loadData"
      :pageSize="15"
    >
      <!-- 会员头像 -->
      <span slot="avatar_url" slot-scope="text">
        <div class="avatar">
          <img v-if="text" width="45" height="45" :src="text" alt="用户头像" />
          <img v-else width="45" height="45" src="~@/assets/img/default-avatar.png" alt="用户头像" />
        </div>
      </span>
      <span slot="main_info" slot-scope="item">
        <p>{{ item.nick_name }}</p>
        <p class="c-p">{{ item.mobile }}</p>
      </span>
      <!-- 操作 -->
      <span class="actions" slot="action" slot-scope="item">
        <a title="修改" v-action:recharge @click="edit(item)">查看/修改进度</a>
      </span>
    </s-table>
  </a-card>
</template>

<script>
import * as Api from '@/api/project/parting'
import { STable } from '@/components'

// 注册来源名称
const PlatformName = {
  'MP-WEIXIN': '微信小程序',
  'H5': 'H5',
  'APP': 'APP',
  'G-WEIXIN': '微信公众号'
}

export default {
  name: 'Index',
  components: {
    STable
  },
  data () {
    return {
      // 注册来源名称
      PlatformName,
      // 当前表单元素
      searchForm: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 正在加载
      isLoading: false,
      // 表头
      columns: [
        {
          title: 'ID',
          dataIndex: 'id'
        },
        {
          title: '疾病类型',
          dataIndex: 'tag'
        },
        {
          title: '报名时间',
          dataIndex: 'create_time'
        },
        {
          title: '会员头像',
          dataIndex: 'avatar_url',
          scopedSlots: { customRender: 'avatar_url' }
        },
        {
          title: '昵称/手机号',
          scopedSlots: { customRender: 'main_info' }
        },
        {
          title: '参与进度',
          dataIndex: 'statustag'
        },
        {
          title: '项目标的',
          dataIndex: 'title'
        },
        {
          title: '操作',
          // dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: param => {
        return Api.getList({ ...param, ...this.queryParam })
          .then(response => {
            return response.data.list
          })
      },
      // 疾病类别列表
      illnessList: []
    }
  },
  created () {
    this.getIllnessList()
  },
  methods: {
    getIllnessList () {
      const that = this
      Api.illnessList()
        .then(response => {
          that.illnessList = response.data.list.data
        })
    },
    // 修改
    edit (item) {
      this.$router.push({ path: '/project/manage/parting_edit', query: { id: item.id } })
    },

    // 确认搜索
    handleSearch (e) {
      e.preventDefault()
      this.searchForm.validateFields((error, values) => {
        if (!error) {
          this.queryParam = { ...this.queryParam, ...values }
          this.handleRefresh(true)
        }
      })
    },

    /**
     * 刷新列表
     * @param Boolean bool 强制刷新到第一页
     */
    handleRefresh (bool = false) {
      this.$refs.table.refresh(bool)
    }

  }
}
</script>

<style lang="less" scoped>
.ant-card-body {
  padding: 22px 29px 25px;
}
.platform {
  .icon {
    font-size: 17px;
  }

  .MP-WEIXIN {
    color: #04be02;
  }
  .H5 {
    color: #e44c27;
  }
}
</style>
